package com.eugene.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eugene.element.FnCalendar;
import com.eugene.element.FxRate;
import com.eugene.util.HibernateUtil;

public class FxRateDAO {
	private final static Logger logger = LoggerFactory.getLogger(FxRateDAO.class);	
	
	public static List<FxRate> getFxRate(){
		List<FxRate> fxRates = new ArrayList<FxRate>();
		Session s = HibernateUtil.currentSession();
		Query qr;
		qr = s.createQuery("from BaseFxRate ");
		fxRates = qr.list();
		HibernateUtil.closeSession();
		return fxRates;
	}
	public static FxRate getFxRate(String ircId){
		FxRate fxRate;
		Session s = HibernateUtil.currentSession();
		Query qr;
		qr = s.createQuery("from BaseFxRate a where a.fxRateId =:param");
		qr.setParameter("param", ircId);
		fxRate = (FxRate)qr.uniqueResult();
//		HibernateUtil.closeSession();
		return fxRate;
	}
	
	
	
	public static List<FxRate> getFxRate(FnCalendar baseDate){
		List<FxRate> fxRates = new ArrayList<FxRate>();
		Session s = HibernateUtil.currentSession();
		s.enableFilter("dateFilter").setParameter("asOfDate", baseDate);
		Query qr;
		qr = s.createQuery("from BaseFxRate ");
		fxRates = qr.list();
//		HibernateUtil.closeSession();
		return fxRates;
	}
	
	public static FxRate getFxRate(String ircId, FnCalendar baseDate){
		FxRate fxRate;
		Session s = HibernateUtil.currentSession();
		s.enableFilter("dateFilter").setParameter("asOfDate", baseDate);
		Query qr;
		qr = s.createQuery("from BaseFxRate a where a.fxRateId =:param");
		qr.setParameter("param", ircId);
		fxRate = (FxRate)qr.uniqueResult();
//		HibernateUtil.closeSession();
		return fxRate;
	}
	
	
//	public static IrCurve getSceIrCurve(String ircId, FnCalendar baseDate, String sceId){
//		IrCurve ir;
//		Session s = HibernateUtil.currentSession();
//		s.enableFilter("dateFilter").setParameter("asOfDate", baseDate);
//		Query qr;
//		qr = s.createQuery("from SceIrCurve a where a.ircId =:param");
//		qr.setParameter("param", ircId);
//		ir = (IrCurve)qr.uniqueResult();
////		HibernateUtil.closeSession();
//		return ir;
//		return ir;
//	}
}
